package net.esj.tree;

import java.util.Locale;

import net.esj.basic.plugins.spring.support.ApplicationResourceBundleMessageSource;

import org.springframework.util.Assert;

public class TreeResourceBundleMessageSource extends
	ApplicationResourceBundleMessageSource {
	
	private static final String DEFAULT_MESSAGE = "net.esj.tree.tree";
	
	private static final String USER_MESSAGE_POSTFIX = "i18n.tree_";
	
	private String moduleKey;
	
	public TreeResourceBundleMessageSource(Locale defaultLocale,String key) {
		super(DEFAULT_MESSAGE, getUserMessage(key), defaultLocale);
		Assert.hasText(key);
		this.moduleKey = key;
	}

	public TreeResourceBundleMessageSource(String key) {
		super(DEFAULT_MESSAGE, getUserMessage(key));
		Assert.hasText(key);
		this.moduleKey = key;
	}

	private static String getUserMessage(String key) {
		StringBuilder sb = new StringBuilder(USER_MESSAGE_POSTFIX);
		sb.append(key);
		return sb.toString();
	}

	public String getModuleKey() {
		return moduleKey;
	}

}
